package cn.itcast.com.network.tcp.exer04;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //创建socket对象
        Socket socket = new Socket("localhost",8888);
        //创建一个输出流
        OutputStream out = socket.getOutputStream();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
        //传输数据
        BufferedReader br = new BufferedReader(new FileReader("D:\\代码\\代码\\代码\\cn\\itcast\\com\\network\\tcp\\exer04\\src.txt"));
        String line;

        while ((line = br.readLine()) != null){
            bw.write(line);
        }
int len;
        bw.flush();
        byte[] bytebuff = new byte[1024];
        //当客户端上传完文件，执行到这里，阻塞等待，
        len  = socket.getInputStream().read(bytebuff);

        System.out.println(new String(bytebuff,0,len));
        //释放资源
        bw.close();
        socket.close();
    }
}
